<?php
//后台图片处理
class ImgEditAction extends BaseAction {
	//彩信图片上传处理
  	function edit(){
   		$type = $_REQUEST['t'];
   		//echo $type;
  		$imgEdit = service('ImgEdit');
  		//upload($baseuploadpath,$reluploadpath,$picname,$width,$height)
  		//dosave($baseuploadpath,$reluploadpath,$picname,$width,$height)
    	if( $type == 'upload' ){
    		$baseuploadpath= 'data/uploads';
    		$reluploadpath= 'imgedit';
    		$picname	= 'original-'.$this->adminId;
    		$width		= 1000;
    		$height		= 1000;
       		echo $imgEdit->upload($baseuploadpath,$reluploadpath,$picname,$width,$height);
   		}elseif ( $type == 'save'){
   			$baseuploadpath	= 'data/uploads';
   			$reluploadpath	= $_REQUEST['relpath'];//要保存的位置
   			$picname		= $_REQUEST['picname'];//参数由前台上传
   			$width			= intval($_REQUEST['towidth']);
   			$height			= intval($_REQUEST['toheight']);
   			//dump($_REQUEST);
       		$relpath = $imgEdit->dosave($baseuploadpath,$reluploadpath,$picname,$width,$height);
       		$result['new_img_rel_path']=$relpath;
			$result['status']=1;
			echo json_encode( $result );
		}
  		exit;     		
  	}
  	
	//kissy编辑器上传
	public function kissy(){

		//执行附件上传操作
		$attach_type	=	'kissy';

		$options['uid']			=	$this->mid;
		$options['allow_exts']	=	'jpg,jpeg,bmp,png,gif';
		$info	=	X('Xattach')->upload($attach_type,$options);
		
		if(is_array($info['info'])){
			//$image_url	=	SITE_URL.'/data/uploads/'.$info['info'][0]['savepath'].$info['info'][0]['savename'];
			$image_url	=	'/data/uploads/'.$info['info'][0]['savepath'].$info['info'][0]['savename'];
		}

		//上传成功
		if($info['status']==true){
			echo '{"status": "0", "imgUrl": "' .$image_url. '"}';
		}else{
			echo '{"status": "1", "error": "'.$info['info'].'"}';
		}
	}
}
?>